#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
int t;
int n,m;
int l,v;
struct edge
{
    int l;
    int r;
};
bool cmp(edge a,edge b){
    if(a.r<b.r)return 1;
    else return 0;
}
vector<edge> g;
int d[MAXN],va[MAXN],a[MAXN];
int mc[MAXN*10];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        g.clear();
        int ans1=0,ans2=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>va[i]>>a[i];
        }
        for(int i=1;i<=l+1;i++){
            mc[i]=0;
        }
        for(int i=1;i<=m;i++){
            int x;
            cin>>x;
            mc[x]++;
            
        }
        for(int i=1;i<=l;i++){
            mc[i]=mc[i]+mc[i-1];
        }
        for(int i=1;i<=n;i++){
            
            double le=0,ri=0;
            if(a[i]==0){
                if(va[i]>v){
                    le=d[i];
                    ri=l+1;
                }else{
                    le=0;
                    ri=0;
                }
                
            }else
            if(a[i]>0){
                if(va[i]>v){
                    le=d[i];
                    ri=l+1;
                }else{
                    ri=l+1;
                    le=(double)(v*v-va[i]*va[i])/(2*a[i])+d[i];
                }
            }else{
                if(va[i]>v){
                    le=d[i];
                    ri=(double)(v*v-va[i]*va[i])/(2*a[i])+d[i];
                }else{
                    le=0;
                    ri=0;
                }
            }
            int lef=ceil(le);
            int rig=floor(ri);
            if(rig>l)rig=l;
            
            if(mc[rig]-mc[lef-1]!=0){
                ans1++;
                g.push_back({lef,rig});

            }
            
        }
        sort(g.begin(),g.begin()+g.size(),cmp);
        for(int i=0;i<g.size();i++){
            if(g[i].l!=-1){
                int p=0;
                for(int j=g[i].l;j<=g[i].r;j++){
                    if(mc[j]-mc[j-1]!=0){
                        p=j;
                    }
                }
                for(int j=0;j<g.size();j++){
                    if(g[j].l<=p&&g[j].r>=p){
                        g[j].l=-1;
                    }
                }
                ans2++;
            }
        }
        cout<<ans1<<" "<<n- ans2<<endl;
    }
    return 0;
}
